# 使用官方 Python 运行时作为父镜像
FROM python:3.12-slim

# 设置工作目录
WORKDIR /app

# 更换为清华源并安装 mysql-client
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \
      echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
      echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
      echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
      apt-get update && \
      apt-get install -y default-mysql-client && \
      rm -rf /var/lib/apt/lists/*

# 将当前目录内容复制到容器的 /app 中
COPY . /app

# static 和 logs 目录不存在时创建
RUN mkdir -p /app/static /app/logs

# 设置启动脚本权限
RUN chmod +x /app/scripts/start.sh

# 安装项目依赖
RUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

# 暴露端口 8000 供外部访问
EXPOSE 8000

# 定义环境变量
ENV ENV=production

# 使用启动脚本
CMD ["/app/scripts/start.sh"]
